package org.tao.lightningmq.nameserver.store;

import io.netty.channel.ChannelHandlerContext;
import org.tao.lightningmq.nameserver.event.model.RegistryEvent;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author lht
 * @date 2025/1/8 - 14:28
 * @description: 接入的服务实例
 */
public class ServiceInstance {

    private String registryType;
    private String ip;
    private Integer port;
    private Long firstRegistryTime;
    private Long lastHeartBeatTime;
    private ChannelHandlerContext context;
    private Map<String,Object> attrs;

    public ServiceInstance() {
    }

    public ServiceInstance(RegistryEvent event) {
        this.registryType = event.getRegistryType();
        this.ip = event.getIp();
        this.port = event.getPort();
        this.firstRegistryTime = System.currentTimeMillis();
        this.attrs = event.getAttrs();
        this.context = event.getContext();
    }

    public String getRegistryType() {
        return registryType;
    }

    public void setRegistryType(String registryType) {
        this.registryType = registryType;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public Long getFirstRegistryTime() {
        return firstRegistryTime;
    }

    public void setFirstRegistryTime(Long firstRegistryTime) {
        this.firstRegistryTime = firstRegistryTime;
    }

    public Long getLastHeartBeatTime() {
        return lastHeartBeatTime;
    }

    public void setLastHeartBeatTime(Long lastHeartBeatTime) {
        this.lastHeartBeatTime = lastHeartBeatTime;
    }

    public Map<String, Object> getAttrs() {
        return attrs;
    }

    public void setAttrs(Map<String, Object> attrs) {
        this.attrs = attrs;
    }

    public ChannelHandlerContext getContext() {
        return context;
    }

    public void setContext(ChannelHandlerContext context) {
        this.context = context;
    }

    @Override
    public String toString() {
        return "ServiceInstance{" +
                "lastHeartBeatTime=" + lastHeartBeatTime +
                ", attrs=" + attrs +
                ", firstRegistryTime=" + firstRegistryTime +
                ", port=" + port +
                ", ip='" + ip + '\'' +
                ", registryType='" + registryType + '\'' +
                '}';
    }
}
